var app =getApp()
let a;

Page({
  data:{

  },
  onShow() {
    var user = app.globalData.vipInfo;
    if (user && user.phone) {
      let shengyu = user.viptime - new Date().getTime()
      console.log("会员剩余时间", shengyu)
      this.setData({
        user: user,
        shengyu,
        vipTimeStr: app._getCurrentTime(user.viptime)
      })
    } else {
      wx.showModal({
        confirmText: "去注册",
        content: "先去注册为用户，才可以充值会员",
        cancelColor: '取消',
        success: res => {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/change/change',
            })
          }
        }
      })
    }
  },

  //获取充值金额
  getamount(e){
    a=e.detail.value;
  },
  chongzhi(){

    let user = this.data.user
   // console.log(user.openid)
  
    wx.request({
      url: app.globalData.baseUrl + '/user/Charge',
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        openid: user.openid,
        money: a,
       
      },
      success(res) {
        if (res && res.data && res.data.data) {
          console.log("充值成功", res.data)
          wx.showToast({
            title: '充值成功',
          })
          let user = app.globalData.vipInfo
          Object.assign(user, res.data.data)
          app.globalData.vipInfo = user
          app._getMyUserInfo();
        }
        // wx.navigateBack();
        wx.switchTab({
          url: '/pages/me/me'
        })
      },
      fail(res) {
        console.log("充值失败", res)
      }
    })
    }
  


})